#!/bin/bash
# Begin tagger.wip
##############
#$# creator : Devon Smith
#%# email: smithde@oclc.org
#$# created : 2010-06-22
#$# title : tagger.wip
#$# description : Command line tagger demo 
########## Define a usage function 
function usage {
    echo "Usage: $this [ format ]"
    echo -e "\t default format = text/x-ner-markup"
    echo -e "\t valid format options = text/x-ner-entities, text/html, application/xml"
    if [ "$1" = "exit" ]; then exit; fi
}
########## Set to "false" to turn verbose off
function echo_stdout { echo "$@"; }
function echo_stderr { echo "$@" >& 2; }
# Set verbose to 'echo_stderr' or 'echo_stdout' to see output trace info
verbose=false
#verbose=echo_stdout
$verbose Verbose output on ${verbose##*_}

########## Setup some common paths
# The absolute, canonical ( no ".." ) path to this script
canonical=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")")
# Just the filename of this script
this=$(basename $canonical)
$verbose This: $this
# The directory this script is in
here=$(dirname $canonical)
$verbose Here: $here

########## When the script is being executed
today=$(date +%F)
now=$(date +%H:%M:%S)
$verbose Time: $today $now
##########
if [ "$1" = "-h" ]; then usage 'exit' ; fi
##########
JAVA=$(which java)

format="text/x-ner-markup"
if [ "$1" != "" ]
then
	format="$1"
fi

moduledir=$(dirname $(dirname $here))
$verbose Module Dir: $moduledir

libdir=$(dirname $moduledir)/lib
$verbose Library Dir: $libdir

for script in $(ls classpath.d/*)
do
	if [ -x $script ]
	then
		cp=$($script $libdir)
		if [ "" == "$CP" ]; then CP=$cp; else CP=$CP:$cp; fi
	fi
done
$verbose Classpath: $CP

CLASS=org.oclc.gateman.CmdLineTagger
# Usage: org.oclc.gateman.CmdLineTagger -d input-dir output-dir [ format ]
# Usage: org.oclc.gateman.CmdLineTagger -f batch-file output-file tagger-properties
tagging_properties=/home/smithde/proj/ndiipp/emp-batch-ner/oclc-ner/src/bash/input/tagger.prop

root=/home/smithde/proj/new-ead/data

#for file in $(ls $root/extract/ead_{29,31}.xml)
for file in $(ls $root/extract)
do
	#if [ "${file##*.}" != "txt" ] 
	#then
	#	continue
	#fi
	if [ "${file%%.*}" != "porter" ] 
	then
		continue
	fi

	file=${file##*/}

	$verbose File: $file
	input_file=$root/extract/$file
	output_file=$root/ner/$file
	$JAVA -Xmx2000m -cp $CP $CLASS -f $input_file $output_file $tagging_properties
done

############
# End tagger.wip
# vim:ts=4:indentexpr=
